import * as Excel from 'exceljs';
/* import { intersection, isNumber } from 'lodash';
import { isNil } from 'lodash'; */

// 更新终端文件
async function updateterminal() {
    const workbook_source = new Excel.Workbook();
    const workbook_target = new Excel.Workbook();
    await workbook_source.xlsx.readFile(`C:\\Users\\zhangtao\\Desktop\\111\\69.xlsx`);
    await workbook_target.xlsx.readFile(`C:\\Users\\zhangtao\\Desktop\\111\\终端.xlsx`);
    const sourceSheet = workbook_source.getWorksheet('Sheet1');
    const sourceCount = sourceSheet.rowCount;
    const targetSheet = workbook_target.getWorksheet('终端安装微步天擎情况台账')
    const targetCount = targetSheet.rowCount;

    for (let index = 1; index <= sourceCount; index++) {
        let find = false;
        const sourceRow = sourceSheet.getRow(index);
        const sourceIp = sourceRow.getCell(1).value;
        const sourceMac = sourceRow.getCell(2).value;
        const sourceName = sourceRow.getCell(3).value.toString().trim();
        for (let targetindex = 2; targetindex <= targetCount; targetindex++) {
            const targetRow = targetSheet.getRow(targetindex);
            const targetName = targetSheet.getCell(`H${targetindex}`).value?.toString().trim();
            /* if (index === 8 && targetindex === 100) {
                console.log('xxxxx',targetName);
            } */
            if (targetName === sourceName) {
                targetSheet.getCell(`T${targetindex}`).value = targetName;
                targetSheet.getCell(`M${targetindex}`).value = sourceIp;
                targetSheet.getCell(`N${targetindex}`).value = sourceMac;
                find = true;
                break;
            }
        }
        if (!find) {
            console.log(index, ':', sourceName);
        }
    }
    await workbook_target.xlsx.writeFile(`C:\\Users\\zhangtao\\Desktop\\111\\终端1.xlsx`);
}
updateterminal();


